import ModuleTemplate from '@/utils/ModuleTemplate';
/** modules名称空间 */
export const namespace = 'app';
const model = {
  name: namespace,
  namespaced: true,
  /** 基本属性 */
  state: {
    keepAliveComponents: []
  },
  /** 从基本数据派生的数据,getters接收state作为其第一个参数，
   * 接受其他 getters 作为第二个参数，如不需要，第二个参数可以省略
   */
  getters: {},
  /** 执行同步操作，包含用于直接修改state的函数 */
  mutations: {
    /** 新增存活组件名称 */
    addKeepAliveComponent(state, payload) {
      const keepAliveComponents = state.keepAliveComponents;
      let ex = false;
      for (let i = 0; i < keepAliveComponents.length; i++) {
        if (keepAliveComponents[i] === payload.componentName) {
          ex = true;
          break;
        }
      }
      if (!ex) {
        keepAliveComponents.push(payload.componentName);
      }
      state.keepAliveComponents = keepAliveComponents;
    },
    /** 删减存活组件名称 */
    subKeepAliveComponent(state, payload) {
      const keepAliveComponents = state.keepAliveComponents;
      for (let i = 0; i < keepAliveComponents.length; i++) {
        if (keepAliveComponents[i] === payload.componentName) {
          keepAliveComponents.splice(i, 1);
          break;
        }
      }
      state.keepAliveComponents = keepAliveComponents;
    }
  },
  /** 异步操作，可调用同步操作函数 */
  actions: {
  },
  /** 子模块 */
  modules: {}
};
const moduleTemplate = new ModuleTemplate(model, {});
export const module = moduleTemplate.createModel();